﻿// TestFor_RtspProtocol.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include "pch.h"
#include <tchar.h>
#include <windows.h>
#include <list>
using namespace std;
#include "../../../../NetEngine_Windows/NetEngine_SourceCode/XyRyNet_CommHdr.h"
#include "../../../../NetEngine_Windows/NetEngine_SourceCode/XyRyNet_ProtocolHdr.h"
#include "../../../../NetEngine_Windows/NetEngine_SourceCode/NetEngine_StreamMedia/StreamMedia_RtspProtocol/RtspProtocol_Define.h"
#include "../../../../NetEngine_Windows/NetEngine_SourceCode/NetEngine_StreamMedia/StreamMedia_RtspProtocol/RtspProtocol_Error.h"

#pragma comment(lib,"../../../../NetEngine_Windows/NetEngine_SourceCode/Debug/StreamMedia_RtspProtocol.lib")
#pragma comment(lib,"Ws2_32.lib")

void TestUDP_RtspProtocol()
{
	int nMsgLen = 0;
	LPCTSTR lpszRTSPUrl = _T("rtsp://127.0.0.1/live/1");
	LPCTSTR lpszSession = _T("3B2241FA");
	TCHAR tszMsgBuffer[1024];

	RTSPPROTOCOL_REQUEST st_RtspRequest;
	RTSPPROTOCOL_RESPONSE st_RtspResponse;
	RTSPPROTOCOL_SETUP st_RtspSetup;

	memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
	memset(&st_RtspRequest, '\0', sizeof(RTSPPROTOCOL_REQUEST));
	memset(&st_RtspResponse, '\0', sizeof(RTSPPROTOCOL_RESPONSE));
	memset(&st_RtspSetup, '\0', sizeof(RTSPPROTOCOL_SETUP));

	RtspProtocol_ClientPacket_Setup(tszMsgBuffer, &nMsgLen, lpszRTSPUrl, IPPROTO_UDP, 1, 63505, 63506);
	RtspProtocol_CoreParse_Parse(&st_RtspRequest, tszMsgBuffer, nMsgLen);
	RtspProtocol_CoreHelp_Transport(st_RtspRequest.st_ExtInfo.tszTransport, &st_RtspSetup.nIPProtol, &st_RtspSetup.nClientRTPPort, &st_RtspSetup.nClientRTCPPort);

	st_RtspSetup.nServerRTPPort = 10001;
	st_RtspSetup.nServerRTCPPort = 10002;
	_tcscpy(st_RtspSetup.tszDestAddr, _T("192.168.1.108"));
	_tcscpy(st_RtspSetup.tszSourceAddr, _T("192.168.1.115"));

	RtspProtocol_CorePacket_Setup(tszMsgBuffer, &nMsgLen, lpszSession, &st_RtspSetup, st_RtspRequest.nCseq);
	RtspProtocol_ClientParse_Parse(&st_RtspResponse, tszMsgBuffer, nMsgLen);
	return;
}
void TestTCP_RtspProtocol()
{
	int nMsgLen = 0;
	LPCTSTR lpszRTSPUrl = _T("rtsp://127.0.0.1/live/1");
	LPCTSTR lpszSession = _T("3B2241FA");
	TCHAR tszMsgBuffer[1024];

	RTSPPROTOCOL_REQUEST st_RtspRequest;
	RTSPPROTOCOL_RESPONSE st_RtspResponse;
	RTSPPROTOCOL_SETUP st_RtspSetup;
	RTSPPROTOCOL_AUTHINFO st_AuthInfo;

	memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
	memset(&st_RtspRequest, '\0', sizeof(RTSPPROTOCOL_REQUEST));
	memset(&st_RtspResponse, '\0', sizeof(RTSPPROTOCOL_RESPONSE));
	memset(&st_RtspSetup, '\0', sizeof(RTSPPROTOCOL_SETUP));
	memset(&st_AuthInfo, '\0', sizeof(RTSPPROTOCOL_AUTHINFO));

	_tcscpy(st_AuthInfo.tszAuthUser, "123123aa");
	_tcscpy(st_AuthInfo.tszAuthPass, "123123");

	RtspProtocol_ClientPacket_Setup(tszMsgBuffer, &nMsgLen, lpszRTSPUrl, IPPROTO_TCP, 1, 1, 2, 3, &st_AuthInfo);
	RtspProtocol_CoreParse_Parse(&st_RtspRequest, tszMsgBuffer, nMsgLen);
	RtspProtocol_CoreHelp_Transport(st_RtspRequest.st_ExtInfo.tszTransport, &st_RtspSetup.nIPProtol, &st_RtspSetup.nClientRTPPort, &st_RtspSetup.nClientRTCPPort);

	RtspProtocol_CorePacket_Setup(tszMsgBuffer, &nMsgLen, lpszSession, &st_RtspSetup, st_RtspRequest.nCseq);
	RtspProtocol_ClientParse_Parse(&st_RtspResponse, tszMsgBuffer, nMsgLen);
	return;
}

int main()
{
	WSADATA st_WSAData;
	WSAStartup(MAKEWORD(2, 2), &st_WSAData);

	TestUDP_RtspProtocol();
	TestTCP_RtspProtocol();
	WSACleanup();
	return 0;
}